﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Less2DB.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            var user = new T_User() { F_ID = 3 };
            var article = new T_Article() { F_ID = 1, F_UserID = user.F_ID };
            var query = new DBQuery();

            try
            {
                var count = 0;

                count = query.ExecuteNonQuery(user, "CREATE TABLE T_User(F_ID INTEGER PRIMARY KEY ASC);");
                count += query.ExecuteNonQuery(article, "CREATE TABLE T_Article(F_ID INTEGER PRIMARY KEY ASC, F_UserID INTEGER ASC);");
                count += query.Add(user);
                count += query.Add(article);
                //query.Fill(article, x => x.F_UserID == 3);
                query.Commit();

                Console.WriteLine(count);
            }
            catch
            {
                query.Rollback();
            }
            finally
            {
                query.Close();
            }

            Console.Read();
        }

        private static Less2DB.Interfaces.IDAL _defaultDAL;

        /// <summary>
        /// 获取默认的数据库引擎。
        /// </summary>
        public static Less2DB.Interfaces.IDAL DefaultDAL
        {
            get
            {
                if (_defaultDAL == null)
                    _defaultDAL = new SQLite.DAL();

                return _defaultDAL;
            }
        }

        /// <summary>
        /// 获取默认的数据库引擎的连接字符串。
        /// </summary>
        public static string DefaultDALConnectionString
        {
            get { return "Data Source=:memory:;Version=3;New=True"; }
        }
    }
}
